﻿using BonjourQuotation.DataAccess.Repositories;
using BonjourQuotation.ObjectModel.AccountData;
using BonjourQuotation.ObjectModel.ErrorData;
using BonjourQuotation.ObjectModel.CustomerData;
using BonjourQuotation.ObjectModel.LoggerData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BonjourQuotation.UI.ServiceManagers
{
    public class CustomerManager
    {
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public ErrorBInfo CreateCustomer(CustomerDetailsBData CustomerData)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.CreateCustomer(CustomerData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ManageCustomersGridBData LoadCustomers(int PageNumber)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomers(PageNumber);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ManageCustomersGridBData LoadCustomerByID(int CustomerID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerByID(CustomerID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ManageCustomersGridBData LoadSearchedCustomers(ManageCustomersGridBData model)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadSearchedCustomers(model);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CustomerDetailsBData LoadCustomerDetailsByID(int CustomerID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerDetailsByID(CustomerID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CustomerGroupsBData LoadCustomerGroupsByID(int CustomerID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerGroupsByID(CustomerID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CustomerInvoicesBData LoadCustomerInvoicesByID(int CustomerID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerInvoicesByID(CustomerID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CustomerPaymentsBData LoadCustomerPaymentsByID(int CustomerID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerPaymentsByID(CustomerID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CustomerGroupsBData LoadCustomerSearchedGroupsByID(int CustomerID,int CustomerStatusID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerSearchedGroupsByID(CustomerID, CustomerStatusID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CustomerQuotationsBData LoadCustomerQuotationsByID(int CustomerID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerQuotationsByID(CustomerID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo SaveCustomersGridData(ManageCustomersGridBData Data)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.SaveCustomersGridData(Data);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo SaveCustomerPaymentsData(CustomerPaymentsBData CustomerPaymentsData)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.SaveCustomerPaymentsData(CustomerPaymentsData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo SaveCustomerPaymentGroupsData(CustomerPaymentGroupsBData CustomerPaymentGroupsData)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.SaveCustomerPaymentGroupsData(CustomerPaymentGroupsData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo CreateCustomerPayment(CustomerPaymentsBData CustomerPaymentData , ref int LineNo)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.CreateCustomerPayment(CustomerPaymentData, ref LineNo);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo CreateCustomerPaymentGroup(CustomerPaymentGroupsBData CustomerPaymentGrData)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.CreateCustomerPaymentGroup(CustomerPaymentGrData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public CustomerPaymentGroupsBData LoadCustomerPaymentGroupsByID(int CustomerID, int? LineNo)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCustomerPaymentGroupsByID(CustomerID, LineNo);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo SaveCustomerDetailsData(CustomerDetailsBData CustomerData)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.SaveCustomerDetailsData(CustomerData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo CreateCustomerContact(CustomerDetailsBData CustomerContactData)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.CreateCustomerContact(CustomerContactData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }
        }
        public Dictionary<string, string> LoadState()
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadState();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public Dictionary<int, string> LoadCity(int CountryID, string StateID)
        {
            try
            {
                var proxy = new CustomerRepository();
                return proxy.LoadCity(CountryID, StateID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
    }
}